/**
 * Copyright 2009 by Christian Scheid. This file is part of the switch eclipse plugin and is licensed under the
 * GPL version 3. Please refer to the URL http://www.gnu.org/licenses/gpl-3.0.html for details.
 */
package org.digitalsoul.switchplugin.prefs.wizards;

import org.digitalsoul.switchplugin.matchers.MatcherType;
import org.digitalsoul.switchplugin.prefs.CriteriaListUI;
import org.digitalsoul.switchplugin.prefs.util.HelpTexts;
import org.digitalsoul.switchplugin.prefs.util.ItemListConfigurator;
import org.eclipse.swt.widgets.Composite;


public class MatcherWizard extends CriteriaWizard {

    private MatcherType type;

    public MatcherWizard(ItemListConfigurator configurator, CriteriaListUI listUI) {
        super(configurator, listUI);
    }
    
    @Override
    public String[] getComboItems() {
        return configurator.getMatcherNames();
    }

    @Override
    protected String getPageId() {
        return "matcherWizardPage";
    }

    @Override
    protected void createBuilderPanelContent() {
        type = MatcherType.valueOf(combo.getItem(combo.getSelectionIndex()).toUpperCase());
        Composite textFieldPanel = createTextFieldPanel("match: ");
        addHelpLabel(textFieldPanel, getExampleText());
        addInverseCheckbox();
    }

    @Override
    public boolean performFinish() {
        configurator.createMatcher(type, text.getText(), checkbox.getSelection());
        listUI.updateListItems();
        listUI.updateButtons();
        return true;
    }

    @Override
    protected boolean isWizardComplete() {
        return text != null && text.getText().trim().length() > 0;
    }
    
    @Override
    protected String getPageDescription() {
        return HelpTexts.getMatcherWizardTitle();
    }

    @Override
    protected String getTitle() {
        return "Add Matcher";
    }

    @Override
    protected String getCheckboxText() {
        return " inverse this matcher";
    }

    @Override
    protected Enum<?> getTypeForItemName(String itemName) {
        return MatcherType.valueOf(itemName.toUpperCase());
    }
}
